[READ-ONLY] a fast, modern browser for the npm registry
at main 33 lines 920 B view raw
1import * as v from 'valibot' 2import { PackageRouteParamsSchema } from '#shared/schemas/package' 3 4/** 5 * GET /api/social/likes/:name 6 * 7 * Gets the likes for a npm package on npmx 8 */ 9export default eventHandlerWithOAuthSession(async (event, oAuthSession, _) => { 10 const pkgParamSegments = getRouterParam(event, 'pkg')?.split('/') ?? [] 11 const { rawPackageName } = parsePackageParams(pkgParamSegments) 12 13 if (!rawPackageName) { 14 throw createError({ 15 status: 400, 16 message: 'package name not provided', 17 }) 18 } 19 20 try { 21 const { packageName } = v.parse(PackageRouteParamsSchema, { 22 packageName: decodeURIComponent(rawPackageName), 23 }) 24 25 const likesUtil = new PackageLikesUtils() 26 return await likesUtil.getLikes(packageName, oAuthSession?.did.toString()) 27 } catch (error: unknown) { 28 handleApiError(error, { 29 statusCode: 502, 30 message: 'Failed to get likes', 31 }) 32 } 33})